<?php


class PictureTable extends Doctrine_Table
{
  public static function getInstance()
  {
    return Doctrine_Core::getTable('Picture');
  }
  
  public function getBackendListQuery(Doctrine_Query $query)
  {
    $rootAlias = $query->getRootAlias();
    
    $user = sfContext::getInstance()->getUser();
    
    if ($user->hasCredential('admin'))
    {
      $query->innerJoin("$rootAlias.contestant c")
        ->andWhereIn('c.area_id', $user->getAreaIds());
    } 
    else if ($user->hasCredential('super'))
    {
      //$query->innerJoin("$rootAlias.publisher p");
    }
    
    return $query;
  }
}